﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyFirstSRPG.SRPGGameLibrary;
using MyFirstSRPG.SRPGGame.GameScreens.SceneScreens;
using Microsoft.Xna.Framework;
using MyFirstSRPG.SRPGGame.Actions;

namespace MyFirstSRPG.SRPGGame
{
	public class Scene00 : SceneScript
	{
		public Scene00()
		{
			this.Title = "Test Scene";
			this.MapSize = new Size(25, 21);

			this.TileSize = new Size(16, 16);

			this.TileSheet = new int[21, 25]
			{
				#region TileSheet

				{0x0007,0x0604,0x0103,0x0704,0x0804,0x0102,0x0a00,0x0203,0x0202,0x0400,0x0107,0x0904,0x0a04,0x0a04,0x0001,0x0600,0x0a00,0x0203,0x0c00,0x0102,0x0a00,0x0301,0x0207,0x0604,0x0103},
				{0x0302,0x0303,0x0c00,0x0704,0x0307,0x0b00,0x0b00,0x0700,0x0402,0x0100,0x0700,0x0400,0x0100,0x0500,0x0400,0x0b00,0x0b00,0x0a00,0x0202,0x0b00,0x0100,0x0a00,0x0203,0x0303,0x0c00},
				{0x0407,0x0302,0x0c00,0x0804,0x0102,0x0b04,0x0403,0x0300,0x0300,0x0300,0x0503,0x0603,0x0700,0x0600,0x0403,0x0300,0x0300,0x0300,0x0300,0x0300,0x0503,0x0603,0x0301,0x0302,0x0c00},
				{0x0301,0x0302,0x0c00,0x0102,0x0000,0x0900,0x0200,0x0500,0x0502,0x0100,0x0703,0x0c04,0x0500,0x0507,0x0200,0x0500,0x0607,0x0707,0x0807,0x0100,0x0200,0x0800,0x0a00,0x0301,0x0c00},
				{0x0a00,0x0301,0x0202,0x0907,0x0100,0x0900,0x0200,0x0401,0x0501,0x0601,0x0100,0x0803,0x0a07,0x0903,0x0005,0x0400,0x0b07,0x0c07,0x0008,0x0400,0x0200,0x0800,0x0100,0x0a00,0x0202},
				{0x0701,0x0108,0x0700,0x0402,0x0000,0x0900,0x0200,0x0801,0x0901,0x0a01,0x0000,0x0208,0x0308,0x0408,0x0200,0x0100,0x0508,0x0608,0x0708,0x0600,0x0200,0x0800,0x0000,0x0000,0x0000},
				{0x0105,0x0701,0x0400,0x0000,0x0500,0x0900,0x0200,0x0101,0x0808,0x0908,0x0500,0x0a08,0x0b08,0x0c08,0x0200,0x0100,0x0400,0x0a03,0x0803,0x0100,0x0200,0x0800,0x0600,0x0000,0x0000},
				{0x0602,0x0001,0x0700,0x0600,0x0402,0x0900,0x0200,0x0400,0x0009,0x0109,0x0209,0x0101,0x0a03,0x0b01,0x0205,0x0309,0x0500,0x0a03,0x0400,0x0903,0x0005,0x0800,0x0305,0x0701,0x0000},
				{0x0405,0x0b03,0x0505,0x0505,0x0000,0x0900,0x0200,0x0700,0x0500,0x0502,0x0409,0x0c01,0x0509,0x0609,0x0c01,0x0605,0x0705,0x0709,0x0502,0x0700,0x0200,0x0800,0x0809,0x0001,0x0000},
				{0x0701,0x0909,0x0305,0x0702,0x0000,0x0900,0x0200,0x0600,0x0401,0x0501,0x0601,0x0100,0x0401,0x0501,0x0601,0x0a09,0x0100,0x0401,0x0501,0x0601,0x0200,0x0800,0x0400,0x0000,0x0000},
				{0x0105,0x0701,0x0b09,0x0001,0x0000,0x0900,0x0200,0x0400,0x0801,0x0901,0x0a01,0x0400,0x0801,0x0901,0x0a01,0x0c09,0x0100,0x0801,0x0901,0x0a01,0x0200,0x0800,0x0700,0x0000,0x0000},
				{0x0602,0x0001,0x000a,0x0700,0x0600,0x0900,0x0200,0x0b00,0x0101,0x0802,0x0b01,0x0b00,0x0101,0x0802,0x0b01,0x010a,0x0b00,0x0101,0x0802,0x0b01,0x0703,0x0c04,0x0805,0x0905,0x0902},
				{0x020a,0x0600,0x0b03,0x0000,0x0000,0x030a,0x0703,0x0500,0x040a,0x0c03,0x0a05,0x0c01,0x0705,0x0c03,0x0a05,0x0c03,0x0c01,0x0605,0x0a02,0x0902,0x0803,0x0000,0x0b05,0x0002,0x0002},
				{0x0405,0x0500,0x050a,0x0100,0x0500,0x0500,0x0500,0x060a,0x0c05,0x0403,0x0300,0x0300,0x0300,0x0300,0x0300,0x0300,0x0503,0x070a,0x0a02,0x0002,0x080a,0x0603,0x090a,0x0201,0x0006},
				{0x0702,0x0a0a,0x0b02,0x0600,0x0402,0x0b0a,0x0c01,0x0c05,0x0500,0x0200,0x0100,0x0700,0x0600,0x0502,0x0100,0x0100,0x0200,0x0c0a,0x0106,0x0201,0x0200,0x0800,0x0000,0x0000,0x0000},
				{0x0001,0x000b,0x0805,0x0905,0x0902,0x0b04,0x0903,0x0300,0x0300,0x0206,0x0b02,0x0100,0x0401,0x0501,0x0601,0x0100,0x0205,0x0300,0x0300,0x0300,0x0206,0x0800,0x0100,0x0000,0x0000},
				{0x0306,0x0100,0x0b05,0x0406,0x0006,0x010b,0x0004,0x0506,0x0506,0x0306,0x0606,0x0500,0x0801,0x0901,0x0a01,0x0600,0x0b02,0x0706,0x0806,0x0706,0x0806,0x0606,0x0400,0x0000,0x0000},
				{0x0500,0x0500,0x020b,0x030b,0x0400,0x0004,0x040b,0x0100,0x0700,0x0600,0x050b,0x0000,0x0101,0x0802,0x0b01,0x0100,0x060b,0x070b,0x0702,0x0100,0x0400,0x0906,0x0104,0x0906,0x0104},
				{0x0c02,0x0902,0x080b,0x090b,0x0700,0x0a0b,0x0004,0x0b0b,0x0c0b,0x0b02,0x0000,0x0100,0x000c,0x0406,0x0000,0x0702,0x010c,0x0602,0x0204,0x0104,0x0304,0x020c,0x0404,0x0a06,0x0504},
				{0x030c,0x0a02,0x0201,0x0400,0x0003,0x0003,0x0000,0x0000,0x0c02,0x040c,0x050c,0x0c02,0x0a02,0x060c,0x0904,0x070c,0x0602,0x0204,0x0304,0x0504,0x0404,0x080c,0x090c,0x0404,0x0504},
				{0x0106,0x0201,0x0003,0x0700,0x0600,0x0400,0x0003,0x0c02,0x0002,0x0201,0x0a0c,0x0002,0x0b0c,0x0201,0x0b03,0x0c0c,0x0204,0x0304,0x0303,0x0b06,0x0c06,0x0a06,0x0103,0x0c06,0x0b06}

				#endregion TileSheet
			}.ToPivot();

			var data = new int[21, 25]
			{
				#region Terrain data
				{01,01,01,01,01,01,02,01,01,02,05,05,06,06,05,02,02,01,01,01,02,01,01,01,01},
				{01,01,01,01,01,02,02,02,02,05,02,02,05,02,02,02,02,02,01,02,05,02,01,01,01},
				{01,01,01,01,01,02,00,00,00,00,00,02,02,02,00,00,00,00,00,00,00,02,01,01,01},
				{01,01,01,01,02,02,00,02,02,05,00,02,02,07,00,02,00,00,00,05,00,02,02,01,01},
				{02,01,01,02,05,02,00,00,00,00,05,02,02,00,00,02,00,00,00,02,00,02,05,02,01},
				{05,02,02,02,02,02,00,00,03,00,02,00,00,00,00,05,02,08,02,02,00,02,02,02,02},
				{06,05,02,02,02,02,00,02,02,02,02,00,10,00,00,05,02,04,02,05,00,02,02,02,02},
				{06,05,02,02,02,02,00,02,02,02,02,02,04,02,00,00,02,04,02,00,00,02,05,02,02},
				{02,02,02,02,02,02,00,02,02,02,04,04,04,04,04,04,04,04,02,02,00,02,02,05,02},
				{05,02,05,05,02,02,00,02,00,00,00,05,00,00,00,04,05,00,00,00,00,02,02,05,02},
				{06,05,05,05,02,02,00,02,00,03,00,02,00,03,00,04,05,00,03,00,00,02,02,02,02},
				{06,05,05,02,02,02,00,02,02,02,02,02,02,02,02,04,02,02,02,02,00,02,02,02,02},
				{06,02,02,02,02,02,00,02,04,04,04,04,04,04,04,04,04,04,04,02,02,02,02,02,02},
				{02,02,07,05,02,02,02,04,04,00,00,00,00,00,00,00,00,02,04,02,00,02,02,02,02},
				{05,07,07,02,02,02,04,04,02,00,05,02,02,02,05,05,00,02,02,02,00,02,02,02,02},
				{05,07,02,02,02,02,00,00,00,00,07,05,00,00,00,05,00,00,00,00,00,02,05,02,02},
				{07,05,02,02,02,07,07,07,07,07,02,02,00,03,00,02,07,02,02,02,02,02,02,02,02},
				{02,02,02,02,02,07,02,05,02,02,02,02,02,02,02,05,02,05,05,05,02,01,01,01,02},
				{02,02,02,02,02,02,07,07,07,07,02,05,02,02,02,05,06,06,06,01,01,01,01,01,01},
				{02,04,02,02,02,02,02,02,02,02,02,02,04,02,05,06,06,06,01,01,01,01,01,01,01},
				{02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,06,06,01,01,01,01,01,01,01,01}
				#endregion Terrain data
			}.ToPivot();

			this.MapData = new Terrain[data.GetLength(0), data.GetLength(1)];

			for (int i = 0; i < data.GetLength(0); i++)
			{
				for (int j = 0; j < data.GetLength(1); j++)
				{
					this.MapData[i, j] = Terrains[data[i, j]];
				}
			}
		}

		protected override void TurnStarted(object sender, EventArgs e)
		{
			if (this.Scene.Turns == 1)
			{
				this.Scene.ChangePhase(TurnPhase.EventPhase);

				List<SceneActor> enemies = new List<SceneActor>();
				var boss1 = new AIActor(9, "雷多利克", 16, 5, Point.Zero)
				{
					Faction = Faction.Enemy,
					MapPoint = new Point(2, 18),
					Moveable = true,
					TargetMapPoint = new Point(20, 1),
					Visible = true
				};
				var boss2 = new AIActor(10, "瓦兹曼", 11, 5, Point.Zero)
				{
					Faction = Faction.Enemy,
					MapPoint = new Point(1, 18),
					Moveable = true,
					TargetActor = boss1,
					Visible = true
				};
				var guard = new AIActor(11, "曼斯塔兵", 54, 1, Point.Zero)
				{
					Faction = Faction.Enemy,
					MapPoint = new Point(3, 18),
					Moveable = true,
					TargetActor = boss1,
					Visible = true
				};

				this.Scene.AddAction(new ActorLoadAction(this.Scene, boss1));
				this.Scene.AddAction(new ActorLoadAction(this.Scene, boss2));
				this.Scene.AddAction(new ActorLoadAction(this.Scene, guard));
				this.Scene.AddAction(new PauseAction(TimeSpan.FromSeconds(1d)));
				this.Scene.AddAction(new PhaseChangeAction(this.Scene, TurnPhase.EnemyPhase));
			}
		}
	}
}